class KthLargest:

    def __init__(self, k: int, nums: List[int]):
        nums.sort(reverse=True)
        self.nums=nums[:k]
        self.k=k

    def add(self, val: int) -> int:
        temp=[]
        try:
            while val>self.nums[-1]:
                temp.append(self.nums.pop())
        except IndexError:
            pass
        self.nums.append(val)
        for i in reversed(temp[:]):
            self.nums.append(i)
        if len(self.nums)>self.k:
            self.nums.pop()
        return self.nums[-1]



# Your KthLargest object will be instantiated and called as such:
# obj = KthLargest(k, nums)
# param_1 = obj.add(val)